/*
 * @Description: 开启服务
 * @Author: Myruun
 * @Date: 2021-04-19 17:03:11
 * @LastEditors: Myruun
 * @LastEditTime: 2021-07-29 10:50:39
 * @FilePath: \serve\serve.ts
 */

const { config } = require("./config/default.ts");

const Koa = require("koa");
const jsonp = require("koa-jsonp");
const bodyParser = require("koa-bodyparser");
const koaBody = require("koa-body")({
  multipart: true, // 允许上传多个文件
});

const app = new Koa();
// 中间件

// app.use(jsonp());
app.use(bodyParser());
// app.use(koaBody);

let serve = {
  open() {
    app.use(require("./router.js").routes()); //作用：启动路由
    app.use(require("./router.js").allowedMethods());
    app.listen(config.port, () => {
      console.log("http://localhost:" + config.port);
    });
  },
};

module.exports = serve;
